#include <graphics.h>
#include <conio.h>
#include <math.h>

#define high  640
#define width 640
#define pi 3.1415926535

void main()
{
	initgraph(high,width);		//初始化 480 x 640 的绘图窗口
	cleardevice();				//clear函数

	int center_x,center_y;		//中心坐标
	int hour_x,hour_y;			//时针终点坐标
	int minute_x,minute_y;		//分针终点坐标
	int second_x,second_y;		//秒针终点坐标
	int hour_length;			//时针长度
	int minute_length;			//分针长度
	int second_length;			//秒针长度
	float hour_angle;			//秒针转过角度
	float minute_angle;			//秒针转过角度
	float second_angle;			//秒针转过角度

	SYSTEMTIME ti;				//定义变量存储系统时间
	GetLocalTime(&ti);			//从系统获取时间
	
	//定义各种变量
	center_x=width/2;
	center_y=high/2;
	hour_length   = width/5;	//时针长度
	minute_length = width/4;	//分针长度
	second_length = width/3;	//秒针长度
	
	BeginBatchDraw();

	circle(center_x,center_y,width/2-30);

	while(1)
	{
	setbkcolor(WHITE);
	outtextxy(center_x,15,"12");
	setbkcolor(WHITE);
	outtextxy(center_x,width-45,"6");
	setbkcolor(WHITE);
	outtextxy(width-40,center_y,"3");
	setbkcolor(WHITE);
	outtextxy(33,center_y,"9");
	//输出“我的时钟”
	setbkcolor(WHITE);
	outtextxy(center_x-25,center_y + width/3,"我的时钟");

	GetLocalTime(&ti);			//从系统获取当前时间
	hour_angle=float(ti.wHour * 2 * pi/12);
	minute_angle=float(ti.wMinute * 2 * pi/60);
	second_angle=float(ti.wSecond * 2 * pi/60);
	
	//时针坐标
	hour_x = int(center_x + hour_length * cos(hour_angle));
	hour_y = int(center_y + hour_length * sin(hour_angle));
	//分针坐标
	minute_x = int(center_x + minute_length * cos(minute_angle));
	minute_y = int(center_y + minute_length * sin(minute_angle));
	//秒针坐标
	second_x = int(center_x + second_length * cos(second_angle));
	second_y = int(center_y + second_length * sin(second_angle));
	
	//绘制时针
	setcolor(RED);
	line(center_x,center_y,hour_x,hour_y);

	//绘制分针
	setcolor(BLUE);
	line(center_x,center_y,minute_x,minute_y);

	//绘制秒针
	setcolor(WHITE);
	line(center_x,center_y,second_x,second_y);

	FlushBatchDraw();
	
	//隐藏之前的所有针
	setcolor(BLACK);
	line(center_x,center_y,minute_x,minute_y);
	setcolor(BLACK);
	line(center_x,center_y,hour_x,hour_y);
	setcolor(BLACK);
	line(center_x,center_y,second_x,second_y);

	}

	EndBatchDraw();

	getch();
	closegraph();				// 关闭绘图窗口
}